package com.opener.common.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author baboy
 * @date 16/12/2016
 */
public class StringUtils {

    public static String formatPlaceholders(String s, Map<String, String> param) {
        String newStr = s;

        try {
            if (param != null) {
                String re = "\\{([^\\{\\}]+)\\}";
                Pattern p = Pattern.compile(re);

                String ph;
                String v;
                for(Matcher m = p.matcher(newStr); m.find(); newStr = newStr.replace(ph, (String)v)) {
                    String k2 = m.group(1) + "";
                    ph = "{" + k2 + "}";
                    v = "";
                    if (param.containsKey(k2)) {
                        Object v2 = param.get(k2);
                        v = v2 == null ? "" : String.valueOf(v2);
                    }
                }
            }
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        return newStr;
    }
}
